<?php

namespace backend\models;

use Yii;
use yii\web\IdentityInterface;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property integer $user_id
 * @property string  $name
 * @property string  $password
 * @property string  $mobile_phone
 * @property string  $last_ip
 * @property string  $last_time
 * @property string  $permission_name
 */
class User extends \yii\db\ActiveRecord
{


    /**
     * @inheritdoc
     */
    public static function tableName ()
    {
        return '{{%user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules ()
    {
        return [
            [ [ 'username' ,  'name', 'password'] , 'required' ] ,

            [ [ 'username' ] , 'string' , 'max' => 10 ] ,
            [ [ 'password' ] , 'string' , 'min' => 6 ] ,

//            [
//                'password_repeat' ,
//                'compare' ,
//                'compareAttribute' => 'password' ,
//                'message'          => '两次密码不一致' ,
//                'skipOnEmpty'      => FALSE ,
//            ] ,
            [ [ 'username' ] , 'unique' , 'message' => '该用户已存在' ] ,
            [
                'mobile_phone' ,
                'match' ,
                'pattern' => '#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#' ,
                'message' => '请输入正确的手机号码' ,
            ] ,
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels ()
    {
        return [
            'id'                 => 'User ID' ,
            'username'           => '账号' ,
            'password'           => '密码' ,
            'name'               => '负责人' ,
            'mobile_phone'       => '手机号' ,
            'last_ip'            => '上一次登录IP' ,
            'last_time'          => '上一次登录时间' ,
        ];
    }
}
